package cn.bb.test;

import cn.bb.entity.PhoneBiz;
import cn.bb.entity.PhoneBizImpl;
import cn.bb.entity.PhoneBizImplProxy;
import cn.bb.util.OutOfStockException;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Demo1 {
    @Test
    public void test1() throws OutOfStockException {
        PhoneBiz phoneBiz = new PhoneBizImpl();
        phoneBiz.buyPhone(50);
        phoneBiz.salePhone(40);
    }
    @Test
    public void test2() throws OutOfStockException {
        PhoneBiz phoneBiz = new PhoneBizImplProxy();//创建代理对象
        //调用代理对象的方法
        phoneBiz.buyPhone(50);
        phoneBiz.salePhone(40);
    }
    @Test
    public void test3() throws OutOfStockException {
        ApplicationContext app =new ClassPathXmlApplicationContext("applicationcontext.xml");
        PhoneBiz pbi = (PhoneBiz) app.getBean("phoneBiz");//是接口类型的
        pbi.buyPhone(100);
        pbi.salePhone(88);
        System.out.println(pbi.getClass().getName());
    }
    @Test
    public void test4() throws OutOfStockException {
        ApplicationContext app =new ClassPathXmlApplicationContext("applicationcontext.xml");
        PhoneBiz pbi = (PhoneBiz) app.getBean("phoneBiz");//是接口类型的
        pbi.buyPhone(10);
        pbi.salePhone(88);
        System.out.println(pbi.getClass().getName());
    }
    @Test
    public void test5() throws OutOfStockException {
        ApplicationContext app =new ClassPathXmlApplicationContext("applicationcontext.xml");
        PhoneBiz pbi = (PhoneBiz) app.getBean("phoneBiz");//是接口类型的
        pbi.buyPhone(100);
        pbi.salePhone(88);

    }
}
